#include <iostream>

using namespace std;

struct student
{
    int year;
    int month;
    int day;
    int weight = year * 365 + month * 30 + day;
};

void paixu(student *stu, int t);

int main()
{
    int t;
    cin >> t;
    student *stu = new student[t];
    for (int i = 0; i < t; i++)
    {
        cin >> stu[i].year;
        cin >> stu[i].month;
        cin >> stu[i].day;
        stu[i].weight = stu[i].year * 365 + stu[i].month * 30 + stu[i].day;
    }
    paixu(stu, t);
    cout << stu[1].year << "-" << stu[1].month << "-" << stu[1].day << endl;
    return 0;
}

void paixu(student *stu, int len)
{
    int i, j;
    student t;
    for (i = 0; i < len - 1; i++)
    {
        for (j = 0; j < len - 1 - i; j++)
        {
            if (stu[j].weight > stu[j + 1].weight)
            {
                t = stu[j];
                stu[j] = stu[j + 1];
                stu[j + 1] = t;
            }
        }
    }
}
